package com.ruoyi.web.controller.system;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysTotal;
import com.ruoyi.system.service.ISysTotalService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 汇总Controller
 * 
 * @author fengzy
 * @date 2022-04-10
 */
@RestController
@RequestMapping("/system/total")
public class SysTotalController extends BaseController
{
    @Autowired
    private ISysTotalService sysTotalService;

    /**
     * 查询汇总列表
     */
    @PreAuthorize("@ss.hasPermi('system:total:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysTotal sysTotal)
    {
        startPage();
        List<SysTotal> list = sysTotalService.selectSysTotalList(sysTotal);
        return getDataTable(list);
    }

    /**
     * 导出汇总列表
     */
    @PreAuthorize("@ss.hasPermi('system:total:export')")
    @Log(title = "汇总", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SysTotal sysTotal)
    {
        List<SysTotal> list = sysTotalService.selectSysTotalList(sysTotal);
        ExcelUtil<SysTotal> util = new ExcelUtil<SysTotal>(SysTotal.class);
        return util.exportExcel(list, "total");
    }

    /**
     * 获取汇总详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:total:query')")
    @GetMapping(value = "/{totalId}")
    public AjaxResult getInfo(@PathVariable("totalId") Long totalId)
    {
        return AjaxResult.success(sysTotalService.selectSysTotalById(totalId));
    }

    /**
     * 新增汇总
     */
    @PreAuthorize("@ss.hasPermi('system:total:add')")
    @Log(title = "汇总", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysTotal sysTotal)
    {
        return toAjax(sysTotalService.insertSysTotal(sysTotal));
    }

    /**
     * 修改汇总
     */
    @PreAuthorize("@ss.hasPermi('system:total:edit')")
    @Log(title = "汇总", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysTotal sysTotal)
    {
        return toAjax(sysTotalService.updateSysTotal(sysTotal));
    }

    /**
     * 删除汇总
     */
    @PreAuthorize("@ss.hasPermi('system:total:remove')")
    @Log(title = "汇总", businessType = BusinessType.DELETE)
	@DeleteMapping("/{totalIds}")
    public AjaxResult remove(@PathVariable Long[] totalIds)
    {
        return toAjax(sysTotalService.deleteSysTotalByIds(totalIds));
    }
}
